/*
 * MyCalendar.java
 * 由于时间关系，部分代码未能加上注释,敬请谅解
 * 或者可以加我QQ：229159701,大家可以做学习交流,我是个对JAVA有浓厚兴趣的人
 * 希望我们能够成为学习上和生活上的好朋友
 * 
 * 程序里面每10秒对备忘录做一次检查，备忘录保存路径为d:/Calendar_Memo/Memo.BOX
 * 保存时未对内容加密,原本是打算采用数据库保存,但由于时间关系没有实现
 * E-mail:h20020654@126.com
 * Created on 2008年5月21日, 下午2:08
 */
package calendar;

import java.awt.Color;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

import javax.swing.JOptionPane;
import javax.swing.JSpinner;
import javax.swing.JTable;
import javax.swing.ListSelectionModel;
import javax.swing.UIManager;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
import javax.swing.table.AbstractTableModel;
import javax.swing.table.DefaultTableModel;

/**
 *
 * @author  啊正
 */
public class MyCalendar extends javax.swing.JFrame implements Runnable {

    /**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	Calendar calendar;
    private int count = 10;
    private String today = "";
    private String finalToday = "";
    private SimpleDateFormat sdfDate = new SimpleDateFormat("yyyy-MM-dd");
    private Date now = new Date();

    /** Creates new form MyCalendar */
    public MyCalendar() {
        initComponents();
        finalToday = sdfDate.format(now);
        setTable();
        setDate();
        updateTable();
        new Thread(this).start();
    }

    public void setTable() {
        //设置此表是否始终大到足以填充封闭视口的高度
        tabDays.setFillsViewportHeight(true);
        //返回此 JTable 所使用的 tableHeader 并设置其背景颜色为浅灰色
        tabDays.getTableHeader().setBackground(Color.lightGray);
        //设置此表是否允许同时存在行选择和列选择
        tabDays.setCellSelectionEnabled(true);
        //将表的选择模式设置为只允许单个选择
        tabDays.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    }

    public void setDate() {
        //使用默认时区和语言环境获得一个日历
        calendar = Calendar.getInstance();
        //更改显示 SpinnerModel 当前值的 JComponent,这里为JSpinner，其模型为 SpinnerNumberModel 的 JSpinner 编辑器，初始值为0000
        spYear.setEditor(new JSpinner.NumberEditor(spYear, "0000"));
        //设置spYear的当前值为当前年年份
        spYear.setValue(calendar.get(Calendar.YEAR));
        //添加侦听器(每次模型更改时)
        spYear.addChangeListener(new ChangeListener() {

            public void stateChanged(ChangeEvent arg0) {
                //当前具体日期(日子)
                int day = calendar.get(Calendar.DAY_OF_MONTH);
                //设置月份
                calendar.set(Calendar.DAY_OF_MONTH, 1);
                //设置日历年份为spYear中选择的数值
                calendar.set(Calendar.YEAR, ((Integer) spYear.getValue()).intValue());
                //得到某年某月的日子的最大值
                int maxDay = calendar.getActualMaximum(Calendar.DAY_OF_MONTH);
                //判断当前日子和选择某年某月后的日子大小情况
                calendar.set(Calendar.DAY_OF_MONTH, day > maxDay ? maxDay : day);
                //更新表格显示
                updateTable();
            }
        });

        //设置cboMonths的当前值为当前月份
        cboMonths.setSelectedIndex(calendar.get(Calendar.MONTH));
        //添加侦听器(每次点击时)
        cboMonths.addActionListener(new java.awt.event.ActionListener() {

            public void actionPerformed(ActionEvent e) {
                int day = calendar.get(Calendar.DAY_OF_MONTH);
                calendar.set(Calendar.DAY_OF_MONTH, 1);
                //设置日历月份为cboMonths中选择的数值
                calendar.set(Calendar.MONTH, cboMonths.getSelectedIndex());
                int maxDay = calendar.getActualMaximum(Calendar.DAY_OF_MONTH);
                calendar.set(Calendar.DAY_OF_MONTH, day > maxDay ? maxDay : day);
                updateTable();
            }
        });
    }

    public void updateTable() {

        final String[] week = {"日", "一", "二", "三",
            "四", "五", "六"
        };

        AbstractTableModel tableModel = new DefaultTableModel() {

            /**
			 * 
			 */
			private static final long serialVersionUID = 1L;

			@Override
            public int getRowCount() {
                return 6;
            }

            @Override
            public int getColumnCount() {
                return 7;
            }

            @Override
            public String getColumnName(int column) {
                return week[column];
            }

            @Override
            public Object getValueAt(int row, int column) {

                Calendar calendar = (Calendar) MyCalendar.this.calendar.clone();
                calendar.set(Calendar.DAY_OF_MONTH, 1);
                int dayCount = calendar.getActualMaximum(Calendar.DAY_OF_MONTH);
                int moreDayCount = calendar.get(Calendar.DAY_OF_WEEK) - 1;
                int index = row * 7 + column;
                int dayIndex = index - moreDayCount + 1;
                if (index < moreDayCount || dayIndex > dayCount) {
                    return null;
                } else {
                    return new Integer(dayIndex);
                }

            }

            @Override
            public boolean isCellEditable(int rowIndex, int columnIndex) {
//                System.out.println("------" + (rowIndex + 1) + "行" + (columnIndex + 1) + "列------");
                return false;
            }
        };
        if (tabDays == null) {
            tabDays = new JTable();
        }
        tableModel.fireTableDataChanged();
        tabDays.setModel(tableModel);
        int day = calendar.get(Calendar.DAY_OF_MONTH);
        for (int i = 0; i < tabDays.getRowCount(); i++) {
            for (int j = 0; j < tabDays.getColumnCount(); j++) {
                if (tabDays.getValueAt(i, j) != null && tabDays.getValueAt(i, j).toString().equals(day + "")) {
                    tabDays.setRowSelectionInterval(i, i);
                    tabDays.setColumnSelectionInterval(j, j);
                }
            }
        }
        if (((calendar.get(Calendar.MONTH) + 1) + "").length() == 1) {
            today = calendar.get(Calendar.YEAR) + "-" + 0 + (calendar.get(Calendar.MONTH) + 1) + "-" + calendar.get(Calendar.DAY_OF_MONTH);
        } else {
            today = calendar.get(Calendar.YEAR) + "-" + (calendar.get(Calendar.MONTH) + 1) + "-" + calendar.get(Calendar.DAY_OF_MONTH);
        }
        new  CheckMemo(today).start();
        setLunar();
    }

    public void run() {
        while (true) {
            Date nowTime = new Date();
            SimpleDateFormat sdfTime = new SimpleDateFormat("HH点mm分ss秒");
            labTime.setText(sdfTime.format(nowTime));
            if (count == 10) {
                new CheckMemo(today);
            }
            try {
                Thread.sleep(1000);
                if (count == 10) {
                    count = 0;
                } else {
                    count++;
                }
            } catch (Exception e) {
            }
        }
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        pm = new javax.swing.JPopupMenu();
        miWriteDayMemo = new javax.swing.JMenuItem();
        contentPane = new javax.swing.JPanel();
        labYear = new javax.swing.JLabel();
        spYear = new javax.swing.JSpinner();
        cboMonths = new javax.swing.JComboBox();
        spTab = new javax.swing.JScrollPane();
        tabDays = new javax.swing.JTable();
        labCount = new javax.swing.JLabel();
        labAllCount = new javax.swing.JLabel();
        labTime = new javax.swing.JLabel();
        panLunar = new javax.swing.JPanel();
        labLunar = new javax.swing.JLabel();
        mb = new javax.swing.JMenuBar();
        mMemo = new javax.swing.JMenu();
        miThatDayMemo = new javax.swing.JMenuItem();
        miAllMemo = new javax.swing.JMenuItem();
        sep = new javax.swing.JSeparator();
        miWriteMemo = new javax.swing.JMenuItem();
        mHelp = new javax.swing.JMenu();
        miHelp = new javax.swing.JMenuItem();
        miAbout = new javax.swing.JMenuItem();

        miWriteDayMemo.setText("写该天备忘录");
        miWriteDayMemo.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                miWriteDayMemoActionPerformed(evt);
            }
        });
        pm.add(miWriteDayMemo);

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("日历");
        setIconImage(Toolkit.getDefaultToolkit().createImage(getClass().getResource("/calendar/today.png")));
        setResizable(false);

        contentPane.setBackground(new java.awt.Color(204, 204, 255));

        labYear.setText("年");

        spYear.setEditor(new javax.swing.JSpinner.NumberEditor(spYear, "2008"));

        cboMonths.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "一月", "二月", "三月", "四月", "五月", "六月", "七月", "八月", "九月", "十月", "十一月", "十二月" }));

        spTab.setBorder(new javax.swing.border.LineBorder(new java.awt.Color(0, 0, 0), 1, true));

        tabDays.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.LOWERED));
        tabDays.setComponentPopupMenu(pm);
        tabDays.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null}
            },
            new String [] {
                "日", "一", "二", "三", "四", "五", "六"
            }
        ) {
            /**
			 * 
			 */
			private static final long serialVersionUID = 1L;
			boolean[] canEdit = new boolean [] {
                false, false, false, false, false, false, false
            };

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        tabDays.setToolTipText("选中后右击可编写该天备忘录");
        tabDays.setSelectionBackground(new java.awt.Color(0, 0, 255));
        tabDays.getTableHeader().setResizingAllowed(false);
        tabDays.getTableHeader().setReorderingAllowed(false);
        tabDays.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                tabDaysMouseClicked(evt);
            }
        });
        spTab.setViewportView(tabDays);

        labCount.setHorizontalAlignment(javax.swing.SwingConstants.TRAILING);
        labCount.setText("<html><div align='center'><font color='black'>该天备忘录：</font><font color='red'>0个</font></div></html>");
        labCount.setToolTipText("双击我");
        labCount.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                labCountMouseClicked(evt);
            }
        });

        labAllCount.setForeground(new java.awt.Color(255, 0, 0));
        labAllCount.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        labAllCount.setText("<html><div align='center'><font color='black'>全部备忘录：</font><font color='red'>0个</font></div></html>");
        labAllCount.setToolTipText("双击我");
        labAllCount.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                labAllCountMouseClicked(evt);
            }
        });

        labTime.setForeground(java.awt.SystemColor.controlDkShadow);
        labTime.setText("09点21分00秒");

        panLunar.setBackground(new java.awt.Color(204, 204, 255));
        panLunar.setBorder(new javax.swing.border.LineBorder(new java.awt.Color(0, 0, 0), 1, true));

        labLunar.setFont(new java.awt.Font("宋体", 0, 14));
        labLunar.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        labLunar.setText("<html><div align='center'><b>2008</b>年<b>5</b>月<b>27</b>日</div><div align='center'><font size='6' color='red'><b>星期二</b></font></div><div align='center'><font size='7' color='blue'><b>农历</b></font></div><p><div align='center'><font size='6'><b>2008年</b></font></div><p><div align='center' color='green'><b>四月廿三</b></div></html>");
        labLunar.setVerticalAlignment(javax.swing.SwingConstants.TOP);

        javax.swing.GroupLayout panLunarLayout = new javax.swing.GroupLayout(panLunar);
        panLunar.setLayout(panLunarLayout);
        panLunarLayout.setHorizontalGroup(
            panLunarLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(labLunar, javax.swing.GroupLayout.DEFAULT_SIZE, 113, Short.MAX_VALUE)
        );
        panLunarLayout.setVerticalGroup(
            panLunarLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(labLunar, javax.swing.GroupLayout.DEFAULT_SIZE, 177, Short.MAX_VALUE)
        );

        javax.swing.GroupLayout contentPaneLayout = new javax.swing.GroupLayout(contentPane);
        contentPane.setLayout(contentPaneLayout);
        contentPaneLayout.setHorizontalGroup(
            contentPaneLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(contentPaneLayout.createSequentialGroup()
                .addGroup(contentPaneLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(contentPaneLayout.createSequentialGroup()
                        .addGap(10, 10, 10)
                        .addGroup(contentPaneLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(contentPaneLayout.createSequentialGroup()
                                .addComponent(labYear)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(spYear, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(cboMonths, javax.swing.GroupLayout.PREFERRED_SIZE, 74, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(labTime))
                            .addGroup(contentPaneLayout.createSequentialGroup()
                                .addComponent(labCount, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addGap(18, 18, 18)
                                .addComponent(labAllCount, javax.swing.GroupLayout.DEFAULT_SIZE, 134, Short.MAX_VALUE))))
                    .addComponent(spTab, javax.swing.GroupLayout.PREFERRED_SIZE, 251, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(panLunar, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
        );
        contentPaneLayout.setVerticalGroup(
            contentPaneLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(contentPaneLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(contentPaneLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(panLunar, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addGroup(contentPaneLayout.createSequentialGroup()
                        .addGroup(contentPaneLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(labYear)
                            .addComponent(spYear, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(cboMonths, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(labTime))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(spTab, javax.swing.GroupLayout.PREFERRED_SIZE, 120, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(contentPaneLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(labCount, javax.swing.GroupLayout.PREFERRED_SIZE, 19, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(labAllCount, javax.swing.GroupLayout.PREFERRED_SIZE, 21, javax.swing.GroupLayout.PREFERRED_SIZE))))
                .addContainerGap())
        );

        mb.setBackground(java.awt.SystemColor.inactiveCaptionText);

        mMemo.setBackground(java.awt.SystemColor.inactiveCaptionText);
        mMemo.setMnemonic('M');
        mMemo.setText("备忘录(M)");

        miThatDayMemo.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_T, java.awt.event.InputEvent.ALT_MASK));
        miThatDayMemo.setText("查该日备忘录");
        miThatDayMemo.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                miThatDayMemoActionPerformed(evt);
            }
        });
        mMemo.add(miThatDayMemo);

        miAllMemo.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_A, java.awt.event.InputEvent.ALT_MASK));
        miAllMemo.setText("查看全部备忘录");
        miAllMemo.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                miAllMemoActionPerformed(evt);
            }
        });
        mMemo.add(miAllMemo);
        mMemo.add(sep);

        miWriteMemo.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_W, java.awt.event.InputEvent.CTRL_MASK));
        miWriteMemo.setText("写备忘录");
        miWriteMemo.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                miWriteMemoActionPerformed(evt);
            }
        });
        mMemo.add(miWriteMemo);

        mb.add(mMemo);

        mHelp.setBackground(java.awt.SystemColor.inactiveCaptionText);
        mHelp.setMnemonic('H');
        mHelp.setText("帮助(H)");

        miHelp.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_F1, 0));
        miHelp.setMnemonic('C');
        miHelp.setText("帮助内容(C)");
        miHelp.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                miHelpActionPerformed(evt);
            }
        });
        mHelp.add(miHelp);

        miAbout.setMnemonic('A');
        miAbout.setText("关于(A)");
        miAbout.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                miAboutActionPerformed(evt);
            }
        });
        mHelp.add(miAbout);

        mb.add(mHelp);

        setJMenuBar(mb);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(contentPane, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(contentPane, javax.swing.GroupLayout.DEFAULT_SIZE, 197, Short.MAX_VALUE)
        );

        java.awt.Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
        setBounds((screenSize.width-389)/2, (screenSize.height-252)/2, 389, 252);
    }// </editor-fold>//GEN-END:initComponents
    private void labCountMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_labCountMouseClicked
        // TODO add your handling code here:
        if (evt.getClickCount() >= 2) {
            if (labCount.getText().trim().equals("<html><div align='center'><font corlor='black'>该天备忘录：</font><font color='red'>0个</font></div></html>")) {
                JOptionPane.showMessageDialog(this, "该日没记录");
                return;
            }
            new MemoRecord(today, finalToday).setVisible(true);
        }
    }//GEN-LAST:event_labCountMouseClicked

    private void labAllCountMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_labAllCountMouseClicked
        // TODO add your handling code here:
        if (evt.getClickCount() >= 2) {
            if (labAllCount.getText().trim().equals("<html><div align='center'><font color='black'>全部备忘录：</font><font color='red'>0个</font></div></html>")) {
                JOptionPane.showMessageDialog(this, "系统备忘录为空");
                return;
            }
            new MemoRecord("allMemo", finalToday).setVisible(true);
        }
}//GEN-LAST:event_labAllCountMouseClicked

    private void miWriteDayMemoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_miWriteDayMemoActionPerformed
        // TODO add your handling code here:
        if (tabDays.getSelectedColumn() == -1) {
            JOptionPane.showMessageDialog(this, "请选择日期");
            return;
        }
        String date = "";
        if (((cboMonths.getSelectedIndex() + 1) + "").length() == 1) {
            date = spYear.getValue().toString() + "-" + 0 + (cboMonths.getSelectedIndex() + 1) +
                    "-" + tabDays.getValueAt(tabDays.getSelectedRow(), tabDays.getSelectedColumn());
        } else {
            date = spYear.getValue().toString() + "-" + (cboMonths.getSelectedIndex() + 1) +
                    "-" + tabDays.getValueAt(tabDays.getSelectedRow(), tabDays.getSelectedColumn());
        }
        if (tabDays.getValueAt(tabDays.getSelectedRow(), tabDays.getSelectedColumn()) == null) {
            JOptionPane.showMessageDialog(this, "日期无效，请选择正确日期!");
            return;
        }
        new WriteMemo(date).setVisible(true);
    }//GEN-LAST:event_miWriteDayMemoActionPerformed

    private void miWriteMemoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_miWriteMemoActionPerformed
        // TODO add your handling code here:
        new WriteMemo(today).setVisible(true);
    }//GEN-LAST:event_miWriteMemoActionPerformed

    private void miAllMemoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_miAllMemoActionPerformed
        // TODO add your handling code here:
        if (labAllCount.getText().trim().equals("<html><div align='center'><font color='black'>全部备忘录：</font><font color='red'>0个</font></div></html>")) {
            JOptionPane.showMessageDialog(this, "系统备忘录为空");
            return;
        }
        new MemoRecord("allMemo", finalToday).setVisible(true);
    }//GEN-LAST:event_miAllMemoActionPerformed

    private void miThatDayMemoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_miThatDayMemoActionPerformed
        // TODO add your handling code here:
        if (labCount.getText().trim().equals("<html><div align='center'><font corlor='black'>该天备忘录：</font><font color='red'>0个</font></div></html>")) {
            JOptionPane.showMessageDialog(this, "该日没记录");
            return;
        }
        new MemoRecord(today, finalToday).setVisible(true);
    }//GEN-LAST:event_miThatDayMemoActionPerformed

    private void tabDaysMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_tabDaysMouseClicked
        // TODO add your handling code here:
        if (tabDays.getValueAt(tabDays.getSelectedRow(), tabDays.getSelectedColumn()) == null) {
            return;
        }
        calendar.set(Calendar.DAY_OF_MONTH, ((Integer) (tabDays.getValueAt(tabDays.getSelectedRow(), tabDays.getSelectedColumn()))).intValue());
        updateTable();
        setLunar();
    }//GEN-LAST:event_tabDaysMouseClicked

    private void miAboutActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_miAboutActionPerformed
        // TODO add your handling code here:
        JOptionPane.showMessageDialog(this, "------啊正作品------\r\nE-mail:h20020654@126.com\r\nQQ:229159701",
                "关于",JOptionPane.INFORMATION_MESSAGE);
    }//GEN-LAST:event_miAboutActionPerformed

    private void miHelpActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_miHelpActionPerformed
        // TODO add your handling code here:
        JOptionPane.showMessageDialog(this, "由于时间和个人能力有限，\r\n若需要请求帮助，请发送E-mail到本人邮箱。" +
                "\r\n或者可以加我QQ联系，\r\n不常在线，请见谅!","帮助内容",JOptionPane.INFORMATION_MESSAGE);
    }//GEN-LAST:event_miHelpActionPerformed

    private void setLunar() {       //这里如果在表格中点击空白处 则会出现异常 但不会影响程序的运行
        calendar.set(Calendar.YEAR, ((Integer) spYear.getValue()).intValue());
        calendar.set(Calendar.MONTH, cboMonths.getSelectedIndex());
        calendar.set(Calendar.DAY_OF_MONTH, ((Integer) tabDays.getValueAt(tabDays.getSelectedRow(), tabDays.getSelectedColumn())).intValue());
        Lunar lunar = new Lunar(calendar);
        String lunarStr = lunar.toString();
        String year = lunarStr.substring(0, 5);
        String lunarMonthAndDay = lunarStr.substring(5);
        labLunar.setText("<html><div align='center'><b>" + calendar.get(Calendar.YEAR) + "</b>年<b>" + (cboMonths.getSelectedIndex() + 1) +
                "</b>月<b>" + calendar.get(Calendar.DAY_OF_MONTH) + "</b>日</div><div align='center'><font size='6' color='red'>" +
                "<b><b>星期" + tabDays.getColumnName(tabDays.getSelectedColumn()) + "</b></b></font></div>" +
                "<div align='center'><font size='7' color='blue'><b>农历</b></font></div><p>" +
                "<div align='center'><font size='6'><b>" + year + "</b></font></div><p>" +
                "<div align='center' color='green'><b>" + lunarMonthAndDay + "</b></div></html>");
    }

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                try {
                    UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsClassicLookAndFeel");
                } catch (Exception e) {
                    e.printStackTrace();
                }
                new MyCalendar().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JComboBox cboMonths;
    private javax.swing.JPanel contentPane;
    public static javax.swing.JLabel labAllCount;
    public static javax.swing.JLabel labCount;
    private javax.swing.JLabel labLunar;
    private javax.swing.JLabel labTime;
    private javax.swing.JLabel labYear;
    private javax.swing.JMenu mHelp;
    private javax.swing.JMenu mMemo;
    private javax.swing.JMenuBar mb;
    private javax.swing.JMenuItem miAbout;
    private javax.swing.JMenuItem miAllMemo;
    private javax.swing.JMenuItem miHelp;
    private javax.swing.JMenuItem miThatDayMemo;
    private javax.swing.JMenuItem miWriteDayMemo;
    private javax.swing.JMenuItem miWriteMemo;
    private javax.swing.JPanel panLunar;
    private javax.swing.JPopupMenu pm;
    private javax.swing.JSeparator sep;
    private javax.swing.JScrollPane spTab;
    private javax.swing.JSpinner spYear;
    private javax.swing.JTable tabDays;
    // End of variables declaration//GEN-END:variables
}
